// pages/mine/mine.js
const app = getApp();
import Dialog from '../../component/vant/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showAlertStatus:false,
    user:{},
    cells:[
      {
        icon:'../../images/gr_jhjl.png',
        title:'进货记录',
        badge:false,
        link:"toMyHistory"
      },
      {
        icon: '../../images/gr_shdz.png',
        title: '收货地址',
        badge: false,
        link:"toMyAddr"
      },
      {
        icon: '../../images/gr_wddd.png',
        title: '我的订单',
        badge: true,
        link:"toMyOrders"
      },
      {
        icon: '../../images/gr_gwc.png',
        title: '购物车',
        badge: false,
        link: "toMyCart"
      },
      {
        icon: '../../images/gr_lxzgs.png',
        title: '联系总公司',
        badge: false,
        link:"bindShowTel"
      }
    ]
  
  },
  bindShowTel:function(){
    Dialog.confirm({
      title: '提示',
      message: '确定拨打电话：400 1515 968 吗？',
      closeOnClickOverlay:true
    }).then(() => {
      // on confirm
      wx.makePhoneCall({
        phoneNumber: '4001515968' // 仅为示例，并非真实的电话号码
      })
    }).catch(() => {
      // on cancel
    });
  },
  viewAvt(e){
    let src = e.currentTarget.dataset.src;
    wx.previewImage({
      urls: [src,],
    })
  },
  toFileapply(){
    wx.navigateTo({
      url: '../fileapply/fileapply',
    })
  },
  myjxs(){
    wx.navigateTo({
      url: '../myjxs/jxs',
    })
  },
  toEdit(){
    wx.navigateTo({
      url:"../updateProfile/updateProfile"
    })
  },
  toMyBanks(){
    wx.navigateTo({url:"../myBanks/myBanks"})
  },
  toMyAddr(){
    wx.navigateTo({url:"../myAddr/myAddr"})
  },
  toMyOrders(){
    wx.navigateTo({url:"../myOrders/myOrders"})
  },
  toMyHistory(){
    wx.navigateTo({url:"../purchaseRecords/purchaseRecords"})
  },
  toMonthly(){
    wx.navigateTo({url:"../monthlySales/monthlySales"})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const user = app.globalData.userInfo;
    console.log('用户个人信息:')
    console.log(user);
    if (!user.dealerType){
      this.setData({
        user,
        cells:[
          {
            icon: '../../images/gr_ydyj.png',
            title: '月度业绩',
            badge: false,
            link: "toMonthly"
          },
          {
            icon: '../../images/gr_sqgmsq.png',
            title: '授权规模申请',
            badge: false,
            link: "toFileapply"
          },
          {
            icon: '../../images/gr_wdyhk.png',
            title: '我的银行卡',
            badge: false,
            link: "toMyBanks"
          },
          {
            icon: '../../images/gr_wdjxs.png',
            title: '我的经销商',
            badge: false,
            link: "myjxs"
          },
          {
            icon: '../../images/gr_jhjl.png',
            title: '进货记录',
            badge: false,
            link: "toMyHistory"
          },
          {
            icon: '../../images/gr_shdz.png',
            title: '收货地址',
            badge: false,
            link: "toMyAddr"
          },
          {
            icon: '../../images/gr_wddd.png',
            title: '我的订单',
            badge: true,
            link: "toMyOrders"
          },{
            icon: '../../images/gr_gwc.png',
            title: '购物车',
            badge: false,
            link: "toMyCart"
          }
        ]
      })
    }
    this.setData({
      user
    })
  },
  toMyCart(){
    wx.navigateTo({url:"../shoppingCar/shoppingCar"})
  },
  toUpProfile(e){
    let name = this.data.user.nickname;
    let addr = this.data.user.location;
    let mobile = this.data.user.mobile;
    wx.navigateTo({
      url: `../updateProfile/updateProfile?name=${name}&&addr=${addr}&&mobile=${mobile}`,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})